package com.ylbh.modules.push;

import com.alibaba.fastjson.JSONObject;
import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.finance.dto.FinanceDTO;
import com.ylbh.common.pojo.finance.dto.FinanceDetailsDTO;
import com.ylbh.common.pojo.finance.dto.FinanceListDTO;
import com.ylbh.common.pojo.finance.vo.FinanceDetailsVO;
import com.ylbh.common.pojo.push.dto.PushDTO;
import com.ylbh.common.utils.*;
import com.ylbh.modules.business.service.ShoppingUserService;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

/**
 * @author mgh
 */
@RestController
@RequestMapping("/push")
public class PushController {

    @Value("${url.pushUrl}")
    private String pushUrl;

    @SysLog("运营推送")
    @PostMapping("/operatorPushByCondition")
    public CommonResult<String> modifyMoneyById(@RequestBody Map<String,Object> stringObjectMap) {
        String s  = null;
        try {
            s = HttpUtils.sendJsonPost(pushUrl, stringObjectMap);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if(StringUtils.isNotBlank(s)){
            JSONObject jsonObject = JSONObject.parseObject(s);
            if("200".equals(jsonObject.getString("code"))){
                return Ref.ok(jsonObject.getString("message"));
            }else {
                return Ref.error(jsonObject.getString("message"));
            }
        }else {
            return Ref.error();
        }
    }

}
